home *** CD-ROM | disk | FTP | other *** search
- /*
- $VER: SVConvert.dopus5 1.2a (21.08.99)
-
- Written by Wayne Newark <wayne@zahadum.u-net.com>, using GoldEd/Pro.
-
- This is an ARexx script for DOpus Magellan that allows you to use Andreas
- Kleinert's excellent SViewNG/SViewII to convert picture files from one format to
- another. It processes all files selected in one or more source listers, ignoring
- those it does not recognise.
-
- It will only work with a registered version of SViewNG/SViewII.
-
- This script can handle both multiple source and destination listers. All the
- selected source files, from all the source listers, will be converted into
- all the destination listers. As part of the conversion process the files are
- renamed. It does this by stripping off all text after the last '.' and
- appending an appropriate suffix.
-
- Example: Converting to PNG - Pic1.iff becomes Pic1.PNG
- Converting to GIF - Pic2.pcx becomes Pic2.GIF
-
- ---------------------------------------------------------------------------
-
- Usage: ARexx DOpus5:ARexx/SVConvert.dopus5 {Qp} format
-
- format - At present this is limited to: JPEG, BMP, PNG, DEEP, PCX,
- ILBM, PBM, RGFX, TIFF and SVG.
-
- Read the Superview-library.guide for further details on supported graphic
- formats.
-
- ---------------------------------------------------------------------------
-
- History:
-
- Read document svconvert.history for details of changes.
-
- */
-
- signal on Syntax /* intercept syntax errors */
- options results /* need results */
- options failat 11 /* external commands are allowed return code 10 */
- lf='a'x /* ascii code for linefeed */
-
- SV_path = 'Serious:Graphics/Superview/SViewII' /* Location and name of SuperView program */
- SV_port = 'SViewII.rx' /* Name of SuperView ARexx Port */
-
- call Initialise
-
- parse arg DOpus_port ' ' format
-
- if DOpus_port='' then
- DOpus_port='DOPUS.1'
-
- address value DOpus_port
-
- lister query source stem sl
- if sl.count=0 then
- do
- dopus request '"'txt_nosrc'"' txt_okay
- exit
- end
-
- lister query dest stem dl
- if dl.count=0 then
- do
- dopus request '"'txt_nodest'"' txt_okay
- exit
- end
-
- /* set variables depending on required output format */
-
- do i=0 to sv.count-1
- parse var sv.i sv_format '|' sv_suffix '|' sv_compression '|' sv_savetype1 '|' sv_savetype2
- if sv_format=format then
- do
- suffix=sv_suffix
- savetype=sv_savetype1
- if sv_compression='Y' then
- do
- dopus request '"'txt_compress'"' txt_yesno
- if rc=1 then
- savetype=sv_savetype2
- end
- leave
- end
- end
-
- if savetype='' then
- do
- dopus request '"'txt_format'"' txt_okay
- exit
- end
-
- /* Start Superview if not already running */
-
- if ~show('p',SV_port) then
- do
- address command 'run >NIL: 'SV_path' -INSTALL_APPMENU=FALSE -INSTALL_APPICON=FALSE -INSTALL_APPWINDOW=FALSE'
- address command 'WaitForPort 'SV_port
- if ~show('p',SV_port) then /* If SuperView fails to start, an error is reported. */
- do
- dopus request '"'txt_sv_notfnd'"' txt_okay
- exit
- end
- SV_Started=1
- end
-
- address value SV_port
- "PUT_ICONS=NO"
- "ERROR_REPORT=NO"
- address value DOpus_port
-
- /* lock the listers here!!! */
-
- do s=0 to sl.count-1
- lister set sl.s busy on
- end
-
- do d=0 to dl.count-1
- lister set dl.d busy on
- end
-
- /* process source lister(s) */
-
- do s=0 to sl.count-1
- lister query sl.s path /* get path of current source lister */
- src_path=strip(result,"B",'"')
- lister query sl.s numselfiles /* get number of selected files */
- number_files=result
- lister query sl.s numselentries /* get total number of selected items */
- total_selected=result
- if number_files>0 then
- do
- complete=(1+dl.count)*number_files
- sofar=0
- lister clear sl.s abort
- lister set sl.s newprogress abort bar name title
- lister set sl.s newprogress title txt_title
- lister set sl.s newprogress bar complete sofar
- do t=1 to total_selected
- sofar=sofar+1 /* increase progress position */
- lister query sl.s firstsel /* obtain selected item */
- src_name=strip(result,"B",'"')
- lister query sl.s entry src_name stem fileinfo /* check for directories */
- if fileinfo.type<0 then
- do
- /* check for icons (those with .info suffix) and ignore them */
- if right(src_name,5)~='.info' then
- do
- lister set sl.s newprogress name txt_loading||src_name
- lister set sl.s newprogress bar complete sofar
- call Load_File
- if SV_status~='No file loaded' then
- do
- lister query sl.s abort
- if result then
- do
- lister set sl.s newprogress off
- dopus request '"'txt_aborted'"' txt_okay
- call The_End
- exit
- end
- call Convert_File
- do d=0 to dl.count-1 /* now save file to all destinations */
- sofar=sofar+1 /* increase progress position */
- if dl.count>1 then
- lister set sl.s newprogress name txt_saving||dest_name||" "||d+1
- else
- lister set sl.s newprogress name txt_saving||dest_name
- lister set sl.s newprogress bar complete sofar
- call Save_File
- lister query sl.s abort
- if result then
- do
- lister set sl.s newprogress off
- dopus request '"'txt_aborted'"' txt_okay
- call The_End
- exit
- end
- end /* end of do */
- call Delete_File
- end
- else
- do
- sofar=sofar+dl.count
- lister select sl.s src_name off /* deselect current file (invalid format) */
- end
- end
- else
- do
- sofar=sofar+dl.count
- lister select sl.s src_name off /* deselect current file (#?.info) */
- end
- end
- else
- do
- lister select sl.s src_name off /* deselect current directory */
- end
- lister refresh sl.s /* refresh current source lister */
- end /* end of do */
- lister set sl.s newprogress off
- end
- end
-
- call The_End
-
- exit
-
- Syntax:
-
- call The_End
-
- address value DOpus_port
- dopus request '"'txt_error_fnd'"' txt_okay
-
- exit
-
-
- /*** Called subroutines or functions follow ***/
-
-
- /*
- ** Tidies up listers etc.
- */
-
- The_End:
-
- /* Reread all destination listers */
-
- /* Unlock any locked listers */
-
- do s=0 to sl.count-1
- lister set sl.s busy off
- end
-
- do d=0 to dl.count-1
- lister query dl.d path /* obtain path of destination lister */
- dest_path=strip(result,"B",'"')
- lister set dl.d busy off
- lister read dl.d dest_path
- end
-
- /* Quit Superview if started by this script */
-
- if SV_Started then
- if show('p',SV_port) then
- do
- address value SV_port
- "QUIT"
- end
- else
- do
- address value SV_port
- "ERROR_REPORT=YES"
- end
-
- return
-
-
- /*
- ** Sets Output File Format and creates new destination file name
- */
-
- Convert_File:
-
- lang=length(src_name)
- posn=lastpos('.',src_name)
- po=lang-posn
-
- /* rename destination filename */
-
- if posn=0 then
- dest_name=src_name || '.' || suffix
- else
- do
- suffix_old=right(src_name,po)
- dest_name=left(src_name,posn) || suffix
- end
-
- if DATATYPE(suffix_old,'N') = 1 then
- dest_name = dest_name || '.' || suffix_old
-
- dest_info.name=dest_name
-
- address value SV_port
- if suffix='GIF' then
- do
- parse var SV_status st ' ' width 'x' height 'x' depth
- if depth>8 then
- do
- "SVOPERATOR=Dither24Bit" /* reduces picture to 8 bit */
- "ACTION"
- end
- end
-
- interpret '"SAVE_TYPE='savetype'"' /* Sets SuperView Savetype */
-
- return
-
-
- /*
- ** Causes Superview to save file to destination lister
- */
-
- Save_File:
-
- address value DOpus_port
-
- lister query dl.d path /* obtain path of destination lister */
- dest_path=strip(result,"B",'"')
-
- dest_file=dest_path||dest_name /* set up complete file name */
-
- if (exists(dest_file) & Overwrite_ind=0) then
- do
- dopus request '"'||dest_file||txt_replace_1'"' txt_replace_2
- if rc=0 then
- return
- if rc=2 then
- Overwrite_ind=1
- end
-
- address value SV_port
-
- interpret '"SAVE='||dest_file||'"'
-
- address value DOpus_port
-
- lister addstem dl.d dest_info /* update destination lister */
- lister refresh dl.d
-
- return
-
-
- /*
- ** Loads current picture into Superview
- */
-
- Load_File:
-
- src_file=src_path||src_name
-
- address value SV_port
- interpret '"LOAD='||src_file||'"'
- 'STATUS=T:SV.status'
-
- if open(ifile,'T:SV.status','R') then
- do
- SV_status=readln(ifile)
- call close ifile
- end
- else
- SV_status='No file loaded'
-
- address value DOpus_port
-
- return
-
-
- /*
- ** Deletes source file.
- **
- ** We need to load a dummy file into SViewII so that it frees up the current file
- ** for deletion.
- */
-
- Delete_File:
-
- address value SV_port
- "LOAD=T:SV.status"
- address value DOpus_port
-
- if (exists(src_file) & Delete_ind=0) then
- do
- dopus request '"'||src_name||txt_delete_1'"' txt_delete_2
- select
- when rc=1 then
- keep=0
- when rc=2 then
- do
- Delete_ind=1
- keep=0
- end
- when rc=3 then
- do
- Delete_ind=2
- keep=2
- end
- otherwise
- keep=1
- end
- end
-
- lister select sl.s src_name off /* deselect current file */
-
- if (Delete_ind=1 | keep=0) then
- do
- pragma('D', src_path)
- address command 'c:delete ' || src_name || ' QUIET FORCE'
- if rc=0 then
- lister remove sl.s src_name
- end
-
- /* lister refresh sl.s refresh current source lister */
-
- return
-
-
- /*
- ** Initialises variables etc.
- */
-
- Initialise:
- SV_Started = 0
- Overwrite_ind = 0
- Delete_ind = 0
-
- if open(language,'ENV:Language','R') then
- lang = READLN(language)
- else
- lang = 'english'
-
- select
- when lang = 'deutsch' then
- do
- txt_nosrc = 'Keine Quelle gewählt.'
- txt_nodest = 'Kein Ziel gewählt.'
- txt_compress = 'Soll ich mit Kompression speichern?'
- txt_okay = 'Ok'
- txt_yesno = 'Ja|Nein'
- txt_format = 'Unbekanntes Format!'
- txt_sv_notfnd = 'SViewII kann nicht gestartet werden,'lf'Bitte den Pfad ÜberprÜfen'
- txt_title = 'Konvertiere Dateien...'
- txt_loading = 'Lade '
- txt_saving = 'Sichere '
- txt_aborted = 'User Abbruch'
- txt_error_fnd = 'Ein Fehler ist aufgetreten!'
- txt_replace_1 = ' existiert bereits.'||lf||'Soll es Überschrieben werden?'
- txt_replace_2 = 'Ja|Alle|Nein'
- txt_delete_1 = ' bearbeitet.'||lf||'Soll es gelöscht werden?'
- txt_delete_2 = 'Ja|Alle|Keines|Nein'
- end
- otherwise
- do
- txt_nosrc = 'No source(s) selected.'
- txt_nodest = 'No destination(s) selected.'
- txt_compress = 'Shall I use compression?'
- txt_okay = 'Ok'
- txt_yesno = 'Yes|No'
- txt_format = 'Unknown Format Specified!'
- txt_sv_notfnd = 'SViewII can not be started,'lf'check the path'
- txt_title = 'Converting files...'
- txt_loading = 'Loading '
- txt_saving = 'Saving '
- txt_aborted = 'User aborted'
- txt_error_fnd = 'An error has occurred!'
- txt_replace_1 = ' exists.'||lf||'Shall I overwrite it?'
- txt_replace_2 = 'Yes|All|No'
- txt_delete_1 = ' processed.'||lf||'Shall I delete it?'
- txt_delete_2 = 'Yes|All|None|No'
- end
- end
-
- /*
- sv.x - <image format>|<suffix>|<compression available?>|<uncompressed savetype>|<compressed savetype>
-
- */
- sv.0 = 'JPEG|jpg|N|JPEG (IJG-JFIF)|x'
- sv.1 = 'BMP|bmp|N|BMP (Win,OS/2)|x'
- sv.2 = 'PNG|png|N|PNG (PiNG)|x'
- sv.3 = 'PCX|pcx|N|PCX V2.5-3.0|x'
- sv.4 = 'DEEP|iff|N|DEEP|x'
- sv.5 = 'ILBM|iff|Y|ILBM uncompressed|ILBM CmpByteRun1'
- sv.6 = 'PBM|pbm|Y|PBM uncompressed|PBM CmpByteRun1'
- sv.7 = 'RGFX|iff|Y|RGFX uncompressed|RGFX XPK-compressed'
- sv.8 = 'SVG|svg|N|SVG Graphics File|x'
- sv.9 = 'TIFF|tiff|N|TIFF V5.0|x'
- sv.10 = 'TGA|tga|N|Targa (TGA)|x'
- sv.11 = 'PGM|pgm|N|PNM PGM (P5)|x'
- sv.12 = 'PPM|ppm|N|PNM PPM (P6)|x'
- sv.13 = 'SGI|sgi|N|SGI|x'
- sv.14 = 'YUVN|iff|N|YUVN (411)|x'
- sv.15 = 'RAS|ras|N|SunRaster (RAS)|x'
- sv.16 = 'ACBM|iff|N|ACBM uncompressed|x'
-
- sv.count = 17
-
- savetype = ''
- suffix = ''
-
- return
-